<?php  
class M_theloai extends CI_model{ 
	 // đếm tổng số record trong table book 
	function get_categories(){
		//$this->db->order_by('parent_id');
		return $this->db->get('theloai')->result_array();
	}
    public function count_all(){ 
        return $this->db->count_all('theloai'); 
    }
	public function listall(){
        $query=$this->db->get("theloai");
        return $query->result_array();
    }
    // lấy dữ liệu theo từng phần 
    public function list_with_page($number, $offset){ 
        $query =  $this->db->get('theloai',$number,$offset); 
        $result_array = $query->result_array();
        /*$i = 0;
        foreach ($result_array as $items) {
            $gia = $items['sanpham_Gia'];
            $result_array[$i]['sanpham_Gia'] = $this->format_price($gia);
            $i++;
        }*/
        return $result_array; 
    } 
	/* function ListAll(){ 
		//$this->db->order_by("theloai_id","desc");
		$this->db->where("TinNoiBat",1);
		$query=$this->db->get('theloai');
		return $query->result_array();
    } */
	function Gettheloai($id){
		$this->db->where("theloai_id",$id);
		$query=$this->db->get('theloai');
		return $query->row_array();
	} 

    function GettheloaiById($id){
        $this->db->where("theloai_id",$id);
        $query=$this->db->get('theloai');
        return $query->row();
    } 


	function GetTheLoaiCha(){
		$this->db->where("TL_AnHien",1);
		$this->db->where("Parent_id",0);
		$query=$this->db->get('theloai');
		return $query->result_array();
	} 
	function GettheloaiByTheLoai($id_theloai){
		$this->db->where("id_theloai",$id_theloai);
		$query=$this->db->get('theloai');
		return $query->result_array();
	}
	function Insert($data){
        $this->db->insert('theloai',$data);
        return $this->db->insert_id();
    }

    function Update($id, $data){
        $this->db->where('TheLoai_id', $id);
        $this->db->update('theloai',$data);
    }

    function DeleteById($TheLoai_id){
        if($TheLoai_id == ""){
            return FALSE;
        }else{
            $this->db->where("TheLoai_id",$TheLoai_id);
            $this->db->delete('theloai');
            //unlink("./upload/" . $file[0]['file_name']); //xóa file upload trong thư mục chứa
            return TRUE;
        }        
    }

    function DeleteByParentId($Parent_id){
        if($Parent_id == ""){
            return FALSE;
        }else{
            $this->db->where("Parent_id",$Parent_id);
            $this->db->delete('theloai');
            //unlink("./upload/" . $file[0]['file_name']); //xóa file upload trong thư mục chứa
            return TRUE;
        }        
    }
}
?>